package com.dycong.common.IO.socket.SSL.ssl;

import org.apache.log4j.Logger;

import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;

/**
 * Created by dycong on 2017/3/28.
 */
public class Configuration {
    private static Properties config;
    static Logger log = org.apache.log4j.Logger.getLogger(Configuration.class);
    static final Path conf = Paths.get("/path/conf");

    public static Properties getConfig() {
        InputStream in = null;
        try {
            if (config == null) {
                synchronized (Configuration.class) {
                    if (config == null) {
                        File configFile = conf.toFile();
                        if (configFile.exists() && configFile.isFile()) {
                            in = new FileInputStream(configFile);
                            config.load(in);
                        }
                    }
                }
            }
        } catch (FileNotFoundException e) {
            log.error("can't find config file: " + e);
        } catch (IOException e) {
            log.error("load config error: " + e);
        } finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                log.error("config in close error: " + e);
            }
        }
        return config;
    }
}
